<?
	$limit_t = 20;	// minute
	$debug = 1;
	$pidlist[0]="";

	$cmd1[0] = "ps -ec | grep ffmpeg";
	$cmd1[1] = "ps -ec | grep JobScheduler";

	for($i=0; $i<2; $i++)
	{
		$result = exec($cmd1[$i], $arrResult, $return_var);
		if($arrResult)
		{
			$count = 0;
			foreach($arrResult as $result)
			{
				preg_match_all("(\d{2}(:)\d{2}(:)\d{2})", $result, $m);
				$r = sscanf($m[0][0], "%d:%d:%d");
				if($r[0]*60+$r[1]>$limit_t)
				{
					preg_match_all("(^\s?[\d]{1,5})", $result, $m2);
					$pidlist[$count++] = $m2[0][0];
				}
			}
		}
		$arrResult = "";
		$first=1;
		foreach($pidlist as $pid)
		{
			if(!$pid)
	            continue;
	
			if($first==1)
			{
				if($debug)
					echo "<pre>"."before)<br/>".$result."<br/>";
				$first=0;
			}
			$cmd2 = "kill -9 $pid";
			$result = exec($cmd2, $arrResult, $return_var);
	
			if($debug)
				echo $cmd2."<br/>";
			$first=2;
		}
		if($debug && $first==2)
		{
			$result = exec($cmd1[$i], $arrResult, $return_var);
			echo "after)<br/>".$result."<br/>"."</pre>";
		}
	}
?>
